<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
   用户名： <input type="text" id="name">
     密码： <input type="text" id="password">
     权限： <input type="text" id="role">
           <input type="button" value="添加" id="btn">
<script>
    function  check(value) {
        if(value == ''){
            return true
        }
    }

    var btn = document.getElementById("btn");

    btn.onclick = function () {
        var name = document.getElementById("name").value;
        var password = document.getElementById("password").value;
        var role = document.getElementById("role").value;

        if(check(name) || check(password) || check(role)){
            alert("请完善用户信息！！！")
        }else{
            var param = {
                "name": name,
                "password": password,
                "role": role
            };

            $.ajax({
                url : "/addUser",
                data : param,
                async : true,
                success: function (result) {
                    alert(result.msg);
                    location.href="users";
                }
            })
        }


    }



</script>
</body>
</html>